package com.knight.mall.service.impl;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.knight.mall.enums.BizSupportCode;
import com.knight.mall.exception.ServiceException;
import com.knight.mall.mappers.ProductMapper;
import com.knight.mall.service.FileUploadService;
import com.knight.mall.service.ProductPropImgsService;

/**
 * 文件上传服务类实现
 * 
 */
@Service("fileUploadService")
public class FileUploadServiceImpl implements FileUploadService {
	private static final Logger logger = LoggerFactory.getLogger(FileUploadServiceImpl.class);

	@Autowired
	ProductMapper productMapper;

	@Autowired
	ProductPropImgsService productPropImgsService;
	
	@Value("${store.dir}")
	private String storeUrl;

	@Override
	public String uploadFile(Long id,InputStream is) throws ServiceException {
		if (is == null) {
			logger.warn(BizSupportCode._2001013.getMsg());
			throw new ServiceException(BizSupportCode._2001013.getCode(), BizSupportCode._2001013.getMsg());
		}
		if (id == null) {
			logger.warn(BizSupportCode._2001020.getMsg());
			throw new ServiceException(BizSupportCode._2001020.getCode(), BizSupportCode._2001020.getMsg());
		}
		String path = "";
		String fulPpath = "";
		return path;
	}
	
	
	public Map<String,String> uploadFileReturnMap(Long id,InputStream is) throws ServiceException {
		
		if (is == null) {
			logger.warn(BizSupportCode._2001013.getMsg());
			throw new ServiceException(BizSupportCode._2001013.getCode(), BizSupportCode._2001013.getMsg());
		}
		if (id == null) {
			logger.warn(BizSupportCode._2001020.getMsg());
			throw new ServiceException(BizSupportCode._2001020.getCode(), BizSupportCode._2001020.getMsg());
		}
		String path = "";
		String fulPpath = "";
		String viewPath = "";
		Map<String,String> pathMap = new HashMap<>();
		pathMap.put("path", path);
		pathMap.put("fulPpath", viewPath);
		return pathMap;
	}
}
